﻿using System;
using System.Reflection;
using VitCode.Castle.Entities;

namespace AMS.Core.Entities
{
    /// <summary>
    /// 资产信息
    /// </summary>
    public class AssetInfo : BaseEntity
    {
        protected AssetType m_AssetType;
        protected string m_Barcode;

        protected BarcodeFormat m_BarcodeFormat;
        protected DateTime m_CheckedDate = DateTime.Now;
        protected string m_Code;
        protected UserGroup m_Department;
        protected DateTime m_DepreciationDate = DateTime.Now;
        protected string m_DepreciationFunction;
        protected double m_DepreciationRate;
        protected double m_DepreciationValue;
        protected double m_DepreciationYears;
        protected string m_ImagePath;
        protected string m_Location;
        protected string m_Manufacturers;
        protected string m_ModelNumber;
        protected string m_Name;
        protected AssetNature m_Nature;
        protected double m_OriginalValue;
        protected string m_ParentBarcode;
        protected string m_SerialNumber;
        protected string m_ShelfLife;
        protected Site m_Site;
        protected string m_SizeInfo;
        protected AssetSource m_Source;
        protected DateTime m_StartUpDate = DateTime.Now;
        protected AssetState m_State;
        protected string m_Supplier;
        private double m_EndValue;
        protected string m_TypeName;
        protected AssetUnit m_Unit;
        protected User m_Users;
        protected double m_UseYears;

        /// <summary>
        /// 资产条形码
        /// </summary>
        public virtual string Barcode
        {
            get { return m_Barcode; }
            set { m_Barcode = value; }
        }

        /// <summary>
        /// 标签格式控制对象
        /// </summary>
        public virtual BarcodeFormat BarcodeFormat
        {
            get { return m_BarcodeFormat; }
            set { m_BarcodeFormat = value; }
        }

        /// <summary>
        /// 资产类型别名
        /// </summary>
        public virtual string TypeName
        {
            get { return m_TypeName; }
            set { m_TypeName = value; }
        }

        /// <summary>
        /// 资产类别
        /// </summary>
        public virtual AssetType AssetType
        {
            get { return m_AssetType; }
            set { m_AssetType = value; }
        }

        /// <summary>
        /// 名称
        /// </summary>
        public virtual string Name
        {
            get { return m_Name; }
            set { m_Name = value; }
        }

        /// <summary>
        /// 编号
        /// </summary>
        public virtual string Code
        {
            get { return m_Code; }
            set { m_Code = value; }
        }

        /// <summary>
        /// 规格型号
        /// </summary>
        public virtual string ModelNumber
        {
            get { return m_ModelNumber; }
            set { m_ModelNumber = value; }
        }

        /// <summary>
        /// 外形尺寸
        /// </summary>
        public virtual string SizeInfo
        {
            get { return m_SizeInfo; }
            set { m_SizeInfo = value; }
        }

        /// <summary>
        /// 单位
        /// </summary>
        public virtual AssetUnit Unit
        {
            get { return m_Unit; }
            set { m_Unit = value; }
        }

        /// <summary>
        /// 地点
        /// </summary>
        public virtual Site Site
        {
            get { return m_Site; }
            set { m_Site = value; }
        }

        /// <summary>
        /// 详细位置
        /// </summary>
        public virtual string Location
        {
            get { return m_Location; }
            set { m_Location = value; }
        }

        /// <summary>
        /// 原价值
        /// </summary>
        public virtual double OriginalValue
        {
            get { return m_OriginalValue; }
            set { m_OriginalValue = value; }
        }

        /// <summary>
        /// 净价值
        /// </summary>
        public virtual double EndValue
        {
            get { return m_EndValue; }
            set { m_EndValue = value; }
        }

        /// <summary>
        /// 资产性质
        /// </summary>
        public virtual AssetNature Nature
        {
            get { return m_Nature; }
            set { m_Nature = value; }
        }

        /// <summary>
        /// 资产来源
        /// </summary>
        public virtual AssetSource Source
        {
            get { return m_Source; }
            set { m_Source = value; }
        }

        /// <summary>
        /// 折旧方法名称
        /// </summary>
        public virtual string DepreciationFunction
        {
            get { return m_DepreciationFunction; }
            set { m_DepreciationFunction = value; }
        }

        /// <summary>
        /// 折旧年限
        /// </summary>
        public virtual double DepreciationYears
        {
            get { return m_DepreciationYears; }
            set { m_DepreciationYears = value; }
        }

        /// <summary>
        /// 年折旧率
        /// </summary>
        public virtual double DepreciationRate
        {
            get { return m_DepreciationRate; }
            set { m_DepreciationRate = value; }
        }

        /// <summary>
        /// 累计折旧金额
        /// </summary>
        public virtual double DepreciationValue
        {
            get { return m_DepreciationValue; }
            set { m_DepreciationValue = value; }
        }

        /// <summary>
        /// 供应商
        /// </summary>
        public virtual string Supplier
        {
            get { return m_Supplier; }
            set { m_Supplier = value; }
        }

        /// <summary>
        /// 出厂编号
        /// </summary>
        public virtual string SerialNumber
        {
            get { return m_SerialNumber; }
            set { m_SerialNumber = value; }
        }

        /// <summary>
        /// 制造商
        /// </summary>
        public virtual string Manufacturers
        {
            set { m_Manufacturers = value; }
            get { return m_Manufacturers; }
        }

        /// <summary>
        /// 保质期
        /// </summary>
        public virtual string ShelfLife
        {
            get { return m_ShelfLife; }
            set { m_ShelfLife = value; }
        }

        /// <summary>
        /// 使用年限
        /// </summary>
        public virtual double UseYears
        {
            get { return m_UseYears; }
            set { m_UseYears = value; }
        }

        /// <summary>
        /// 状态
        /// </summary>
        public virtual AssetState State
        {
            get { return m_State; }
            set { m_State = value; }
        }

        /// <summary>
        /// 所属部门
        /// </summary>
        public virtual UserGroup Department
        {
            get { return m_Department; }
            set { m_Department = value; }
        }

        /// <summary>
        /// 使用人
        /// </summary>
        public virtual User Users
        {
            get { return m_Users; }
            set { m_Users = value; }
        }

        /// <summary>
        /// 第一次验收日期
        /// </summary>
        public virtual DateTime CheckedDate
        {
            get { return m_CheckedDate; }
            set { m_CheckedDate = value; }
        }

        /// <summary>
        /// 启用时间
        /// </summary>
        public virtual DateTime StartUpDate
        {
            get { return m_StartUpDate; }
            set { m_StartUpDate = value; }
        }

        /// <summary>
        /// 父资产
        /// </summary>
        public virtual string ParentBarcode
        {
            get { return m_ParentBarcode; }
            set { m_ParentBarcode = value; }
        }

        public virtual string ImagePath
        {
            get { return m_ImagePath; }
            set { m_ImagePath = value; }
        }

        /// <summary>
        /// 记录自动折旧日期,tiger: 2010-08-26 add 
        /// </summary>
        public virtual DateTime DepreciationDate
        {
            get { return m_DepreciationDate; }
            set { m_DepreciationDate = value; }
        }

        /// <summary>
        /// 重写Equals方法
        /// </summary>
        public override bool Equals(object obj)
        {
            if (ReferenceEquals(obj, this))
                return true;
            if (obj == null)
                return false;
            var sObj = obj as AssetInfo;
            return sObj != null && (sObj.Id == m_Id || (sObj.Barcode == m_Barcode));
        }

        /// <summary>
        /// 重写GetHashCode方法
        /// </summary>
        public override int GetHashCode()
        {
            int hash = 155;
            hash = 15*hash*m_Id.GetHashCode();
            return hash;
        }

        /// <summary>
        /// 重写ToString方法
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return m_Barcode;
        }

        public virtual Type GetHistoryObjectType()
        {
            return Assembly.Load("AMS.History").GetType("AMS.History.Entities.AssetInfoRecord");
        }
    }
}